package com.manong.bookstore.store.controller;

import com.manong.common.utils.PageUtils;
import com.manong.common.utils.R;
import com.manong.bookstore.store.entity.StoreEntity;
import com.manong.bookstore.store.service.StoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 *
 *
 * @author cyq
 * @email 465447222@qq.com
 * @date 2021-01-27  21:38:42
 *
 * TODO 后台人员可以根据自己的检查规则来检查身份，只有系统管理员才能调用此接口
 */
@RestController
@RequestMapping("storeAdmin/store")
public class StoreAdminController {
    @Autowired
    private StoreService storeService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = storeService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{storeId}")
    public R info(@PathVariable("storeId") Integer storeId){
        StoreEntity store = storeService.getById(storeId);

        return R.ok().put("store", store);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody StoreEntity store){
        storeService.save(store);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody StoreEntity store){
        storeService.updateById(store);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] storeIds){
        storeService.removeByIds(Arrays.asList(storeIds));

        return R.ok();
    }

}
